<?php

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * @see Zend_Gdata_Extension
 */
require_once 'Zend/Gdata/Extension.php';

/**
 * @see Zend_Gdata_Finance
 */
require_once 'Zend/Gdata/Finance.php';

/**
 * Data model class to represent Symbol
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Gdata_Finance_Extension_Symbol extends Zend_Gdata_Extension
{
	protected $_rootNamespace = 'gf';
	protected $_rootElement = 'symbol';
	/**
	 * The Stock Exchange (NYSE,NASDAQ...)
	 *
	 * @var string $_exchange
	 */
	protected $_exchange = null;
	/**
	 * The Listed Company Name
	 *
	 * @var string $_fullName
	 */
	protected $_fullName = null;
	/**
	 * The Ticker
	 *
	 * @var string $_symbol
	 */
	protected $_symbol = null;

	/**
	 * Constructs a new Zend_Gdata_Finance_Extension_price object.
	 * @param string $exchange (optional) Stock Exchange (NYSE,NASDAQ).
	 * @param string $fullName (optional) The Full name of the company or fund.
	 * @param string $symbol (optional) Security ticker symbol.
	 */
	public function __construct($exchange = null, $fullName = null,$symbol = null)
	{
		parent::__construct();
	 foreach (Zend_Gdata_Finance::$namespaces as $nsPrefix => $nsUri) {
	 	$this->registerNamespace($nsPrefix, $nsUri);
	 }
	 $this->_exchange = $exchange;
	 $this->_fullName = $fullName;
	 $this->_symbol = $symbol;
	}

	/**
	 * Retrieves a DOMElement which corresponds to this element and all
	 * child properties.  This is used to build an entry back into a DOM
	 * and eventually XML text for sending to the server upon updates, or
	 * for application storage/persistence.
	 *
	 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
	 * @return DOMElement The DOMElement representing this element and all
	 * child properties.
	 */
	public function getDOM($doc = null)
	{
		$element = parent::getDOM($doc);
		if ($this->_exchange != null) {
			$element->setAttribute('exchange', $this->_exchange);
		}
		if ($this->_fullName != null) {
			$element->setAttribute('fullName', $this->_fullName);
		}
		if ($this->_symbol != null) {
			$element->setAttribute('symbol', $this->_symbol);
		}

		return $element;
	}

	/**
	 * Given a DOMNode representing an attribute, tries to map the data into
	 * instance members.  If no mapping is defined, the name and value are
	 * stored in an array.
	 *
	 * @param DOMNode $attribute The DOMNode attribute needed to be handled
	 */
	protected function takeAttributeFromDOM($attribute)
	{
		switch ($attribute->localName) {
			case 'exchange':
				$this->_exchange = $attribute->nodeValue;
				break;
			case 'fullName':
				$this->_fullName = $attribute->nodeValue;
				break;
			case 'symbol':
				$this->_symbol = $attribute->nodeValue;
				break;
			default:
				parent::takeAttributeFromDOM($attribute);
				break;
		}
	}

	/**
	 * Get the child value for this elements attribute.
	 *
	 * @return string
	 */
	public function getExchange()
	{
		return $this->_exchange;
	}

	/**
	 * Set the value for this elements money attribute.
	 *
	 * @param string $exchange  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_Symbol
	 */
	public function setExchange($exchange=null)
	{
		$this->_exchange = $exchange;
		return $this;
	}

	/**
	 * Get the child value for this elements attribute.
	 *
	 * @return $string of fullName
	 */
	public function getFullName()
	{
		return $this->_fullName;
	}

	/**
	 * Set the value for this elements money attribute.
	 *
	 * @param string $fullName  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_ticker.
	 */
	public function setFullName($fullName)
	{
		$this->_fullName = $fullName;
		return $this;
	}

	/**
	 * Get the child value for this elements attribute.
	 *
	 * @return string of ticker
	 */

	public function getSymbol()
	{
		return $this->_symbol;
	}

	/**
	 * Set the value for this elements attribute.
	 *
	 * @param string $symbol  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_Symbol.
	 */
	public function setSymbol($symbol)
	{
		$this->_symbol = $symbol;
		return $this;
	}
}
